package com.ppl.server.model;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.github.jmkgreen.morphia.annotations.Entity;
import com.github.jmkgreen.morphia.annotations.Id;
import com.github.jmkgreen.morphia.annotations.Indexed;
import com.github.jmkgreen.morphia.annotations.PrePersist;
import org.bson.types.ObjectId;

/**
 * User: Vincent
 * Date: 11/13/12
 * Time: 9:55 AM
 */
@Entity( noClassnameStored = true)
//@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.PROPERTY, property = "@class")
public abstract class DbEntity {
    @Id
    @JsonIgnore
    public ObjectId id;
    @Indexed(unique = true)
    public String identifier;

    public long creationTimestamp;

    public ObjectId getId() {
        return id;
    }

    public void setId(ObjectId id) {
        this.id = id;
    }

    public String getIdentifier() {
        return identifier;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public long getCreationTimestamp() {
        return creationTimestamp;
    }

    public void setCreationTimestamp(long creationTimestamp) {
        this.creationTimestamp = creationTimestamp;
    }


    @PrePersist
    private void persist(){
        if(creationTimestamp <= 0){
            creationTimestamp = System.currentTimeMillis();
        }
    }
}
